﻿namespace Sidvall.Business
{
    public class BusinessExceptionContext
    {
        #region Public Members

        public string Title { get; set; }
        public string Message { get; set; }
        public string ErrorCode { get; set; }

        #endregion
        #region Factory Members

        #region CreateContext

        public static BusinessExceptionContext CreateContext(BusinessException exception)
        {
            if (exception == null)
                throw new System.ArgumentNullException(nameof(exception));

            return new BusinessExceptionContext()
            {
                Title = exception.Title,
                Message = exception.Message,
                ErrorCode = exception.ErrorCode,
            };
        }

        #endregion
        #region Deserialize

        public static BusinessExceptionContext Deserialize(string value)
        {
            return Deserialize(value, null);
        }
        public static BusinessExceptionContext Deserialize(string value, BusinessExceptionContext defaultValue)
        {
            return Sidvall.Serialization.SerializerManager.Current.TryDeserialize<BusinessExceptionContext>(value, () =>
            {
                return defaultValue;
            });
        }

        #endregion

        #endregion
        #region Constructors

        public BusinessExceptionContext()
        {
        }

        #endregion
    }
}
